<template>
  <div>
      <!-- 背景大图 -->
    <div class="topheader">
        <div class="img">
            <img :src="singerurl" alt="">
        </div>
        <div class="title">
            {{singername}}&nbsp;
            <span class="iconfont icon-xihuan" v-show="t==0" @click="gz"></span>
            <span class="iconfont icon-xihuan1 sc1" v-show="t==1" @click="gz"></span>
        </div>
        <div class="button" @click="$router.go(-1)">
            <span class="iconfont icon-xiangzuojiantou"></span>
            {{singername}}
        </div>
    </div>
    <!-- 歌曲列表 -->
    <dl class="musicList">
        <dt @click="AllPlay">
            <i class="iconfont icon-bofang"></i>播放全部<span>(共{{songlist.length}}首)</span>
        </dt>
        <dd v-for="(item,index) in songlist" :key="index" @click="songsBtn(item.id)">
             <!-- v-for="(item,index) in playlist.tracks" :key="item.id" @click="setId(item.id)" -->
            <h1>{{index+1}}</h1>
            <div class="info">
                <h2>{{item.name}}</h2>
                <h3><span>{{item.ar[0].name}}</span></h3>
            </div>
        </dd>
       
    </dl>
  </div>
</template>

<script>
import {getArtistSongs,getArtists,getFollow} from "../api/singersong"
import { Toast } from 'vant';

export default {
    data(){
        return{
            songlist:[],
            singerurl:null,
            singername:null,
            t:0,// 是否关注
        }
    },
    methods:{
        // 播放全部音乐
        AllPlay(){
            this.$emit("get-player-id",this.songlist[0].id)
        },
        // 播放歌曲
        songsBtn(id){
            console.log(id);
            this.$emit("get-player-id",id)
        },
        // 关注按钮
        gz(){
            this.t = this.t==1?0:1;
            if(this.t ==1){
                Toast("关注成功")
            }else{
                Toast("取消关注")
            }
            this.getFollowFun();
            console.log(this.t)
        },
        // 关注用户接口
        getFollowFun(){
            getFollow({id:this.$route.query.id,t:this.t}).then(data=>{
                console.log(data,this.$route.query.id)
            })
        },
        // 获取歌手全部歌曲
        getArtistSongsFun(){
            // console.log(this.$route)
            getArtistSongs({id:this.$route.query.id}).then(data=>{
                this.songlist = data.songs
                console.log(data)
            })
        },
        // 获取歌手详情
        getArtistsFun(){
            getArtists({id:this.$route.query.id}).then(data=>{
                console.log('歌手详情',data)
                this.singerurl = data.artist.img1v1Url;
                this.singername = data.artist.name;
            })
        }
    },
    created(){
        this.getArtistSongsFun();
        this.getArtistsFun();
        // console.log(this.$route.query.id)
    }
}
</script>

<style lang="less">
 .topheader{
        position: relative;
        height: 270px;
        .img{
            width: 100%;
            height: 270px;
            position: relative;
            img{
                position: absolute;
                top:0px;
                left:0px;
                right: 0px;
                bottom: 0px;
                margin:auto;
                width: 100%;
            }
        }
        .title{
            font-size: 18px;
            position: absolute;
            left:18px;
            bottom:18px;
            color:#fff;
            .sc1{
                color: red;
                font-size: 18px;
            }
        }
        .button{
            font-size: 18px;
            position: absolute;
            left:12px;
            top:12px;
            color:#fff;
        }
    }
     .musicList{
        background-color: #fff;
        width: 100%;
        border-radius: 7px;
        position: relative;
        top:-7px;
        padding-bottom:50px;
        dt{
            height: 36px;
            line-height: 36px;
            font-size: 16px;
            color:#454747;
            border-bottom: 1px solid #E3E3E3;
            span{
                font-size: 14px;
                color:#797B7A;
            }
            i{
                width: 44px;
                text-align: center;
                display: inline-block;
            }
        }
        dd{
            border-bottom: 1px solid #E3E3E3;
            height: 53px;
            display: flex;
            h1{
                flex: 0 0 44px;
                line-height: 53px;
                text-align: center;
                font-size: 16px;
                color:#6D6E6E;
            }
            .info{
                flex:1;
                h2{
                    font-size: 16px;
                    color:#1B1C1C;
                    margin-top: 10px;
                    height: 21px;
                    overflow: hidden;
                }
                h3{
                    font-size: 12px;
                    color:#929393;
                    height: 16px;
                    overflow: hidden;
                }
            }
        }
    }

</style>
